version: "3.7"

# For local development, only database is running
#
# docker-compose up -d
#

# https://github.com/vercel/next.js/blob/canary/examples/with-docker-compose/docker-compose.dev.yml

services:
  app:
    container_name: app
    build:
      context: .
      dockerfile: dev.Dockerfile
    volumes:
      - .:/app
      - /app/node_modules
      - /app/.next
    ports:
      - "3000:3000"
    environment:  
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/${POSTGRES_DB}?schema=public
    env_file:
      - .env.local
    restart: always
    depends_on:
      - database

  database:
    container_name: database
    restart: unless-stopped
    image: postgres:latest
    volumes:
      - database_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    ports:
      - "${POSTGRES_PORT}:5432"

volumes:
  database_data:
